Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Printing /
Chapter 3 - Page Formatting and Dialog Box Customization / Customizing QuickDraw GX Dialog Boxes


Parsing Page Ranges

You can install an override function for the gxParsePageRange message, which allows you to check the validity of page numbers that the user selects in the Print dialog box. You must override this message if you allow the user to specify application-specific page ranges, such as "Chapter 5."

Listing 3-28 shows a function, MyPrintDialog, which is called in response to the user choosing the Print menu item from the File menu. The MyPrintDialog function installs an override for the gxParsePageRange message, sets up a default page range, and calls the GXPrintDialog function to display the dialog box with the default page range. After the pages have been printed, or if an error occurred while setting up the default page range, the override function for the gxParsePageRange message is removed.

Listing 3-28 Installing an override function for the gxParsePageRange message

OSErr MyPrintDialog(MyDocumentPtr myDocument)
{
   OSErr             err;
   gxDialogResult    result;
   gxEditMenuRecord  editMenuRec;

   /* Install an override function to parse page ranges. */
   GXInstallApplicationOverride(myDocument->documentJob,
                              gxParsePageRange,
                              MyParsePageRangeOverride);
   .
   .
   .
   err = MySetupDefaultPageRange(myDocument); /* not shown */
   nrequire(err, CouldNotConfigurePageRange);

   /*
      Display the Print dialog box. If there are no errors and
      the user selects the "OK" button, call a printing routine
      to output the pages.
   */
   result = GXJobPrintDialog(myDocument->documentJob,
                            &editMenuRec);
   err = GXGetJobError(myDocument->documentJob);
   if ((err == noErr) && (result == gxOKSelected))
      err = MyPrintDocument(myDocument); /* not shown */
   .
   .
   .

   /* Remove the parse page range override function. */
CouldNotConfigurePageRange:
   GXInstallApplicationOverride(myDocument->documentJob,
                               gxParsePageRange, nil);
   return err;
}
The MySetupDefaultPageRange function that sets up a page range is not shown. For examples of setting up page ranges, see "Specifying Page Ranges in the Job Collection" on page 3-33. The MyPrintDocument function that prints pages is not shown. For information about printing pages, see the chapter "Core Printing Features" in this book.

Listing 3-29 shows the override function, MyParsePageRangeOverride, which calls another function, MyPageRangeValidityCheck, to validate the page range.

Listing 3-29 Override function for the gxParsePageRange message

OSErr MyParsePageRangeOverride(StringPtr fromString, 
               StringPtr toString, gxParsePageRangeResult *result)
{

   /*
      Determine if the "To page" and "From page" strings are
      valid.  If not, the MyPageRangeValidityCheck routine
      returns gxRangeBadFromValue or gxRangeBadToValue.
      Otherwise it will return gxRangeParsed.
   */
   if (*result == gxRangeNotParsed)
      *result = MyPageRangeValidityCheck(fromString, toString);

   return noErr;
}
The MyPageRangeValidityCheck function is not shown. It returns gxRangeParsed if the page range is valid, otherwise it returns gxRangeBadFromValue if the From value is invalid or gxRangeBadToValue if the To value is invalid. For information about parse page range constants, see "The Panel Setup Structure" on page 3-101.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help